package com.nf.health.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.nf.health.app.R;
import com.nf.health.app.customview.CircleImageView;
import com.nf.health.app.models.SearchMainDocBean;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by changpeng on 2017/4/11 0011.
 */

public class SearchNewDoctorAdapter extends RecyclerView.Adapter {



    private Context mContext;
    private List<SearchMainDocBean> mBean;

    public SearchNewDoctorAdapter(Context context, List<SearchMainDocBean> bean) {
        this.mContext = context;
        this.mBean = bean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_new_searchmain_doc, parent, false);
        return new ContentHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SearchMainDocBean searchMainDocBean = mBean.get(position);
        if(searchMainDocBean == null){
            return;
        }
        if (holder instanceof ContentHolder) {
            ContentHolder h = (ContentHolder)holder;
            ImageLoaderUtils.getinstance(mContext).getImage(h.mIvPersonalDocItemSerch, searchMainDocBean.getHimg(), R.drawable.default_head);
            h.mTvName.setText(TextUtils.isEmpty(searchMainDocBean.getNick()) ? "未填写" : searchMainDocBean.getNick());
            h.mTvProfession.setText(searchMainDocBean.getDepartment() + " | " + searchMainDocBean.getProfessional());
            h.mTvMerit.setText(searchMainDocBean.getGoodremedy());
        }

    }

    @Override
    public int getItemCount() {
        if(mBean == null){
            return 0;
        }
        return mBean.size();
    }


    class ContentHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_personal_doc_item_serch)
        CircleImageView mIvPersonalDocItemSerch;
        @Bind(R.id.tv_name)
        TextView mTvName;
        @Bind(R.id.tv_profession)
        TextView mTvProfession;
        @Bind(R.id.tv_merit)
        TextView mTvMerit;
        public ContentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
